﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Quick Start - Layui</title>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <!--弹出框-->
    <div style="padding:20px;" id="popup">
        <form class="layui-form" lay-filter="demo-val-filter" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">付款计划时间</label>
                <div class="layui-input-block layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-date"></i>
                    </div>
                    <input type="text" name="scheduleTime" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">付款比例</label>
                <div class="layui-input-block">
                    <input type="text" name="paymentRatio" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">付款金额(不含税)</label>
                <div class="layui-input-block">
                    <input type="text" name="paymentAmount" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">预付款</label>
                <div class="layui-input-block">
                    <select name="advance">
                        <option value="0">请选择</option>
                        <option value="1">是</option>
                        <option value="2">否</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="text" name="remark" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block" style="float:right">
                    <button type="reset" class="layui-btn layui-btn-primary">返回</button>
                    <button type="submit" id="component" class="layui-btn layui-btn-normal" lay-submit lay-filter="demo-val">确定</button>
                </div>
            </div>
        </form>
    </div>



    <script>
        // 使用layui的layer模块
        layui.use(['form', 'layer'], function () {
            var $ = layui.$;
            var form = layui.form;
            var laydate = layui.laydate;

            console.log(location.search.split("=")[1])

            // 日期
            laydate.render({
                elem: '#date'
            });

            // 提交事件
            form.on('submit(demo-val)', function (data) {
                var field = data.field; // 获取表单字段值
                field.invoiceAmount = 0;//开票金额
                field.amountPaid = 0;//已付款金额
                field.createdOwner = localStorage.getItem('userName');
                field.purchaseNumber = location.search.split("=")[1];//获取订单编码
                console.log(field) //在控制台显示值
                // 此处可执行 Ajax 等操作
                $.ajax({
                    type: "post",
                    url: '@ViewBag.RedDragonWrite' + "/api/Purchase/CreatePayment",
                    data: JSON.stringify(field),
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        // 处理响应，例如提示成功信息
                        layui.layer.msg(res.msg, { icon: 6, time: 1000 });
                        // 使用setTimeout来延迟关闭操作
                        setTimeout(function () {
                            // 操作成功后关闭当前弹出层
                            var index = parent.layer.getFrameIndex(window.name); // 获取当前弹出层的索引
                            parent.layer.close(index); // 关闭弹出层
                        }, 1000);
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        layui.layer.msg('添加失败', { icon: 5, time: 1000 });
                    }
                })
                return false; // 阻止默认 form 跳转
            });
        });
    </script>
</body>
</html>
